package com.xiaozhu.common.https;

import android.view.View;
import android.widget.TextView;

import com.xiaozhu.common.R;
import com.xiaozhu.library.activity.BaseActivity;
import com.xiaozhu.library.entity.EventBusEntity;
import com.xiaozhu.library.http.exception.ApiException;
import com.xiaozhu.library.http.observer.HttpRxObservable;
import com.xiaozhu.library.http.observer.HttpRxObserver;
import com.xiaozhu.library.widget.custom.TitleBarView;

import io.reactivex.disposables.Disposable;

/**
 * @说明 网络请求
 * @作者 LY
 * @时间 2017/12/21 16:34
 * @邮箱 2743569843@qq.com
 * @版权 Copyright(c) 2017 LY-版权所有
 * @备注
 */
public class HttpsActivity extends BaseActivity {
    private TitleBarView titleBar;
    private TextView tvInfo;

    @Override
    public void initView() {
        titleBar = this.findViewById(R.id.titleBar);
        tvInfo = this.findViewById(R.id.tvInfo);
        titleBar.setTitle("网络请求");
        titleBar.setBtnLeft(R.mipmap.icon_back, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        titleBar.setBtnTvRight("请求", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getHttpData();
            }
        });
    }

    @Override
    public void business() {

    }

    @Override
    public int getLayoutResID() {
        return R.layout.activity_https;
    }


    private void getHttpData() {
        HttpRxObserver httpRxObserver = new HttpRxObserver("getWeather") {

            @Override
            protected void onStart(Disposable d) {
                showProgress();
            }

            @Override
            protected void onError(ApiException e) {
                tvInfo.setText("onError:" + e.getMsg());
                hideProgress();
            }

            @Override
            protected void onSuccess(Object response) {
                tvInfo.setText(response.toString());
                hideProgress();
            }
        };
        HttpRxObservable.getObservableObject(ApiUtils.getWeatherApi().getWeather("CN101210101", "7d0bd9bb7b2646c6a00eae68d304e25c ")).subscribe(httpRxObserver);
    }
}
